package com.ling.pl.security.service;

import com.ling.pl.security.model.DefaultUser;
import com.ling.pl.system.service.DictionaryEntity;
import com.ling.pl.system.service.DictionaryGenerator;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

@Component
public class AllUserDictionaryGenerator implements DictionaryGenerator {

    @Resource
    DefaultUserService userService;

    @Override
    public List<DictionaryEntity> getDictionaryEntities() {
        Collection<DefaultUser> users = userService.loadUsers(new HashMap());
        List<DictionaryEntity> results = new ArrayList<DictionaryEntity>();
        for (DefaultUser user : users) {
            DictionaryEntity dictionaryEntity = new DictionaryEntity();
            dictionaryEntity.setCode(user.getUsername());
            dictionaryEntity.setName(user.getCname());
            results.add(dictionaryEntity);
        }
        return results;
    }

    @Override
    public String getDictType() {

        return "ALLUSER";
    }

}
